package com.yanqu.road.server.pb;

import com.yanqu.road.entity.activity.stelesoul.SteleSoulIndexData;
import com.yanqu.road.entity.activity.stelesoul.SteleSoulMapData;
import com.yanqu.road.entity.activity.stelesoul.SteleSoulUserData;
import com.yanqu.road.entity.activity.stelesoul.config.SteleSoulConfig;
import com.yanqu.road.entity.activity.stelesoul.config.SteleSoulMapConfig;
import com.yanqu.road.entity.activity.stelesoul.config.SteleSoulPeriodConfig;
import com.yanqu.road.entity.activity.stelesoul.config.SteleSoulReviewConfig;
import com.yanqu.road.pb.activity.SteleSoulProto;
import com.yanqu.road.server.manger.activity.stelesoul.SteleSoulMgr;
import com.yanqu.road.utils.property.Property;

import java.util.List;
import java.util.Map;

public class SteleSoulPb {
    public static SteleSoulProto.SteleSoulUserDataMsg.Builder parseSteleSoulUserDataMsg(SteleSoulUserData data) {
        SteleSoulProto.SteleSoulUserDataMsg.Builder builder = SteleSoulProto.SteleSoulUserDataMsg.newBuilder();
        builder.setRoundTimes(data.getRound());
        builder.setLoop(data.getCircle());
        Map<Integer, SteleSoulMapData> map = data.getMapData();
        for (Integer mapKey : map.keySet()){
            SteleSoulProto.SteleSoulMapDataMsg.Builder mapDataBuilder = SteleSoulProto.SteleSoulMapDataMsg.newBuilder();
            List<SteleSoulIndexData> indexList = map.get(mapKey).getSteleSoulIndexDataMsg();
            for(int i = 0; i < indexList.size();i++){
                SteleSoulProto.SteleSoulIndexDataMsg.Builder indexBuilder = SteleSoulProto.SteleSoulIndexDataMsg.newBuilder();
                indexBuilder.setIndex(i);
                indexBuilder.setReward(indexList.get(i).getReward());
                indexBuilder.setState(indexList.get(i).getState());
                mapDataBuilder.addIndexList(i, indexBuilder);
            }
            mapDataBuilder.setCircle(mapKey);
            builder.addIndexData(mapKey, mapDataBuilder);
        }
        builder.setLastIndex(data.getLastIndex());
        for (Map.Entry<Integer, List<Property>> entry : data.getChosenReward().entrySet()) {
            Integer round = entry.getKey();
            SteleSoulProto.SteleSoulChoseTemp.Builder choseBuilder = SteleSoulProto.SteleSoulChoseTemp.newBuilder();
            choseBuilder.setRound(round);
            for (Property reward : entry.getValue()) {
                choseBuilder.addChoseReward(reward.toHelperString());
            }
            builder.addChose(choseBuilder);
        }

        return builder;
    }

    public static SteleSoulProto.SteleSoulMapConfigMsg.Builder parseSteleSoulMapConfigMsg(SteleSoulMapConfig config) {
        SteleSoulProto.SteleSoulMapConfigMsg.Builder builder = SteleSoulProto.SteleSoulMapConfigMsg.newBuilder();
        builder.setPeriod(config.getPeriod());
        builder.setCircle(config.getCircle());
        builder.setSurprisePlaid(config.getSurprisePlaid());
        builder.setReward(config.getReward());
        builder.setSurpriseReward(config.getSurpriseReward());
        return builder;
    }

    public static SteleSoulProto.SteleSoulPeriodConfigMsg.Builder parseSteleSoulPeriodConfigMsg(SteleSoulPeriodConfig config) {
        SteleSoulProto.SteleSoulPeriodConfigMsg.Builder builder = SteleSoulProto.SteleSoulPeriodConfigMsg.newBuilder();
        builder.setId(config.getId());
        builder.setLayer(config.getLayer());
        builder.setConsume(config.getConsume());
        return builder;
    }

    public static SteleSoulProto.SteleSoulReviewConfigMsg.Builder parseSteleSoulReviewConfigMsg(SteleSoulReviewConfig config) {
        SteleSoulProto.SteleSoulReviewConfigMsg.Builder builder = SteleSoulProto.SteleSoulReviewConfigMsg.newBuilder();
        builder.setLayer(config.getLayer());
        builder.setAward(config.getAward());
        builder.setIsReview(config.getIsReview());
        builder.setRewardList(config.getRewardList());
        builder.setSelectReward(config.getSelectReward());
        return builder;
    }

    public static SteleSoulProto.SteleSoulSyncConfigRespMsg.Builder parseSteleSoulSyncConfigRespMsg(SteleSoulConfig config){
        SteleSoulProto.SteleSoulSyncConfigRespMsg.Builder builder = SteleSoulProto.SteleSoulSyncConfigRespMsg.newBuilder();
        for (Map<Integer, SteleSoulMapConfig> map : config.getSteleSoulMapConfig().values()) {
            for(SteleSoulMapConfig value : map.values()){
                builder.addMapConfig(parseSteleSoulMapConfigMsg(value));
            }
        }
        for (SteleSoulPeriodConfig value : config.getSteleSoulPeriodConfig().values()) {
            builder.addPeriodConfig(parseSteleSoulPeriodConfigMsg(value));
        }
        for (SteleSoulReviewConfig value : config.getSteleSoulReviewConfigMap().values()) {
            builder.addReviewConfig(parseSteleSoulReviewConfigMsg(value));
        }
        return builder;
    }

    public static  SteleSoulProto.SteleSoulIndexDataMsg.Builder parseSteleSoulIndexDataMsg(int index, SteleSoulIndexData data){
        SteleSoulProto.SteleSoulIndexDataMsg.Builder builder = SteleSoulProto.SteleSoulIndexDataMsg.newBuilder();
        builder.setIndex(index);
        builder.setReward(data.getReward());
        builder.setState(data.getState());
        return builder;
    }
}
